﻿'/* Copyright (c) 2009, Graeme Grant (graeme@live.com.au)
' * All rights reserved.
' *
' * Redistribution and use in source and binary forms, with or without
' * modification, are permitted provided that the following conditions are met:
' *
' *   * Redistributions of source code must retain the above copyright
' *     notice, this list of conditions and the following disclaimer.
' * 
' *   * Redistributions in binary form must reproduce the above copyright
' *     notice, this list of conditions and the following disclaimer in the
' *     documentation and/or other materials provided with the distribution.
' * 
' *   * The name Graeme Grant may not be used to endorse or promote products
' *     derived from this software without specific prior written permission.
' *
' * THIS SOFTWARE IS PROVIDED BY GRAEME GRANT ``AS IS'' AND ANY
' * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
' * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
' * DISCLAIMED. IN NO EVENT SHALL Dr. WPF BE LIABLE FOR ANY
' * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
' * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
' * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
' * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
' * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
' * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
' */

Imports System.Xml.Serialization
Imports System.IO
Imports System.Drawing

<Serializable()> _
Public Class Feedback

#Region "Constructor"

    Public Sub New()

    End Sub

    Public Sub New(ByVal Details As Hashtable)
        ExtractDetails(Details)
    End Sub

    Friend Sub New(ByVal _json As String)
        ExtractDetails(CType(JSON.JsonDecode(_json), Hashtable)("results")(0))
    End Sub

#End Region

#Region "Public Properties"

    <XmlElement("url")> _
    Private _url As String
    Public Property URL() As String
        Get
            Return _url
        End Get
        Set(ByVal value As String)
            _url = value
        End Set
    End Property

    <XmlElement("creation_epoch")> _
    Private _creation As Date
    Public Property Creation() As Date
        Get
            Return _creation
        End Get
        Set(ByVal value As Date)
            _creation = value
        End Set
    End Property

    <XmlElement("feeback_id")> _
    Private _feeback_id As Long
    Public Property FeebackID() As Long
        Get
            Return _feeback_id
        End Get
        Set(ByVal value As Long)
            _feeback_id = value
        End Set
    End Property

    <XmlElement("author_user_id")> _
    Private _author_user_id As Long
    Public Property AuthorUserID() As Long
        Get
            Return _author_user_id
        End Get
        Set(ByVal value As Long)
            _author_user_id = value
        End Set
    End Property

    <XmlElement("subject_user_id")> _
    Private _subject_user_id As Long
    Public Property SubjectUserID() As Long
        Get
            Return _subject_user_id
        End Get
        Set(ByVal value As Long)
            _subject_user_id = value
        End Set
    End Property

    <XmlElement("seller_user_id")> _
    Private _seller_user_id As Long
    Public Property SellerUserID() As Long
        Get
            Return _seller_user_id
        End Get
        Set(ByVal value As Long)
            _seller_user_id = value
        End Set
    End Property

    <XmlElement("buyer_user_id")> _
    Private _buyer_user_id As Long
    Public Property BuyerUserID() As Long
        Get
            Return _buyer_user_id
        End Get
        Set(ByVal value As Long)
            _buyer_user_id = value
        End Set
    End Property

    <XmlElement("message")> _
    Private _message As String
    Public Property Message() As String
        Get
            Return _message
        End Get
        Set(ByVal value As String)
            _message = value
        End Set
    End Property

    <XmlElement("disposition")> _
    Private _disposition As Enums.disposition
    Public Property Disposition() As Enums.disposition
        Get
            Return _disposition
        End Get
        Set(ByVal value As Enums.disposition)
            _disposition = value
        End Set
    End Property

    <XmlElement("value")> _
    Private _value As Long
    Public Property Value() As Long
        Get
            Return _value
        End Get
        Set(ByVal value As Long)
            _value = value
        End Set
    End Property

    <XmlElement("image_url_25x25")> _
    Private _image_url_25x25 As String
    Public Property ImageURL25x25() As String
        Get
            Return _image_url_25x25
        End Get
        Set(ByVal value As String)
            _image_url_25x25 = value
        End Set
    End Property

    <XmlElement("image_url_fullxfull")> _
    Private _image_url_fullxfull As String
    Public Property ImageURLFullxFull() As String
        Get
            Return _image_url_fullxfull
        End Get
        Set(ByVal value As String)
            _image_url_fullxfull = value
        End Set
    End Property

#End Region

#Region "Support Methods & Functions"

    Private Sub ExtractDetails(ByVal Details As Hashtable)

        _url = Details("url")
        _creation = JSON.DecodeDateTime(Details("creation_epoch"))
        _feeback_id = JSON.ToInteger(Details("feedback_user_id"))
        _author_user_id = JSON.ToInteger(Details("author_user_id"))
        _subject_user_id = JSON.ToInteger(Details("subject_user_id"))
        _seller_user_id = JSON.ToInteger(Details("seller_user_id"))
        _buyer_user_id = JSON.ToInteger(Details("buyer_user_id"))
        _message = Details("message")
        _value = JSON.ToInteger(Details("value"))
        Select Case Details("disposition")
            Case "positive" : _disposition = Enums.disposition.positive
            Case "negative" : _disposition = Enums.disposition.negative
            Case "neutral" : _disposition = Enums.disposition.neutral
        End Select
        _buyer_user_id = JSON.ToInteger(Details("user_id"))
        _image_url_25x25 = Details("image_url_25x25")
        _image_url_fullxfull = Details("image_url_fullxfull")

    End Sub

#End Region

End Class
